package homework04;

import java.util.Scanner;

public class Test {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		GetAqlUtility mySql = new GetAqlUtility();
		int isContinue;
		System.out.println("请输入一个类名：");
		Scanner input = new Scanner(System.in);
		String className = input.next();// 得到类名
		String totalInfo = "homework04" + "." + className;// 类名全体信息
		Class<?> clazz = null;
		try {
			clazz = Class.forName(totalInfo);// 加载类
		} catch (Exception e) {
			System.out.println("类加载错误！");
		}
		System.out.println("你需要新建一个" + className + "表");
		while (true) {
			System.out.println("请输入表数据>>");
			System.out.println("添加sql语言:\n" + mySql.insert(clazz));
			System.out.print("继续创建？(1.继续 2.退出)：");
			isContinue = input.nextInt();
			if (isContinue == 2) {// 退出输入循环
				break;
			}
		}
		System.out.println("新建表如下：");
		mySql.display();// 得到表信息
		System.out.println("");
		while (true) {
			System.out.println("1.插入");
			System.out.println("2.删除");
			System.out.println("3.修改");
			System.out.println("0.退出");
			System.out.println("请输入你想进行的操作对应的序号：");
			int choice = input.nextInt();
			if (choice == 1 || choice == 2 || choice == 3 || choice == 0) {
				switch (choice) {
				case 1:
					System.out.println("添加操作的sql语言:\n" + mySql.insert(clazz));
					System.out.println("添加数据后的表如下：");
					mySql.display();
					break;
				case 2:
					System.out.println("删除操作的sql语言:\n" + mySql.delete(clazz));

					System.out.println("删除数据后的表如下：");
					mySql.display();
					break;
				case 3:
					System.out.println("更新操作的sql语言:\n" + mySql.update(clazz));

					System.out.println("更新数据后的表如下：");
					mySql.display();
					break;
				case 0:
					return;
				}
				System.out.println("\n");
			} else {
				System.out.println("输入不合法，请重新输入！");
			}
		}
	}

}
